<template>
    <section class="product-list-item" @click="handleClick">
        <header class="product-list-item-header">
            <van-image width="100%" :src="imageUrl"/>
        </header>
        <div class="product-content">
            <span class="product-name van-multi-ellipsis--l2">{{product.name}}</span>
            <price :value="product.price" :size="24"/>
        </div>
    </section>
</template>

<script>
  import Price from "@/components/Price"
  import * as _ from "lodash"
  import { Image } from "vant"
  import { catalog } from "@mall/api-services"

  export default {
    name: "ProductListItem",
    components: {
      Price,
      [Image.name]: Image,
    },
    props: {
      product: catalog.Product,
    },
    data() {
      return {}
    },
    computed: {
      imageUrl: function() {
        return _.first(this.product.imageUrls)
      },
    },
    methods: {
      handleClick: function() {
        this.$router.push(`/products/${this.product.id}`)
      },
    },
  }
</script>

<style lang="scss" scoped>

    .product-list-item {
        width: calc(50% - 8px);
        box-sizing: border-box;
        margin: 4px;
        background: #fff;
        border-radius: 6px;

        .product-list-item-header {
            width: 100%;
            text-align: center;

            .van-image {
                overflow: hidden;
                border-radius: 6px;
            }
        }

        .product-name {
            font-size: 14px;
            line-height: 1rem;
        }

        .product-content {
            margin: 6px;
        }

    }
</style>
